<?php
// Prevenir que jquery se cargue dos veces
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
    'id' => 'contacto-form',
    'type' => 'horizontal',
    'action' => Yii::app()->createUrl('/crm/contacto/create'),
    'enableAjaxValidation' => true,
    'clientOptions' => array('validateOnSubmit' => false, 'validateOnChange' => false,),
    'enableClientValidation' => false,
        ));
?>

<div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h4><i class="icon-user"></i> Nuevo Contacto</h4>
</div>
<div class="modal-body">
    <div class="control-group">
        <label class="control-label"><?php echo $form->labelEx($model, 'nombre') ?></label>
        <div class="controls">
            <?php echo $form->hiddenField($model, 'cuenta_id') ?>
            <?php echo $form->dropDownList($model, 'titulo', array('Sr.' => 'Sr.', 'Srta.' => 'Srta.', 'Sra.' => 'Sra.'), array('empty' => '(Ninguno)', 'class' => 'span8')) ?>
            <?php echo $form->error($model, 'titulo'); ?>
        </div>
    </div>
    <div class="control-group" >
        <div class="controls controls-row">
            <?php echo $form->textField($model, 'nombre', array('maxlength' => 32, 'class' => 'span8', 'placeholder' => "Nombre")) ?>
            <?php echo $form->error($model, 'nombre'); ?>
        </div>
    </div>
    <div class="control-group" >
        <div class="controls controls-row">
            <?php echo $form->textField($model, 'apellido', array('maxlength' => 32, 'class' => 'span8', 'placeholder' => "Apellido*")) ?>
            <?php echo $form->error($model, 'apellido'); ?>
        </div>
    </div>

    <?php echo $form->textFieldRow($model, 'documento', array('maxlength' => 20, 'class' => 'span8 ID')) ?>
    <?php echo $form->textFieldRow($model, 'cargo', array('maxlength' => 64, 'class' => 'span8')) ?>
    <?php echo $form->textFieldRow($model, 'departamento', array('maxlength' => 64, 'class' => 'span8 ')) ?>
    <?php echo $form->textAreaRow($model, 'descripcion', array('rows' => 3, 'class' => 'span12')) ?>

    <?php
    $cuentaPermiso = Cuenta::model()->findByPk($model->cuenta_id);
    $model->owner_id = $cuentaPermiso->owner_id;
    $model->permisos = $cuentaPermiso->permisos;
    ?>
    <?php if ($grupos): ?>

        <?php echo $form->checkBoxListRow($model, 'grupos', CHtml::listData($grupos, 'id', 'nombre'), array_map('AweHtml::getPrimaryKey', $model->grupos)); ?>

    <?php endif; ?>
    <div class="well permisos <?php
    if (Yii::app()->user->isSuperAdmin && $model->permisos == 'ALL') {
        echo '';
    } else {
        echo 'hidden';
    }
    ?> ">
             <?php echo $form->dropDownListRow($model, 'owner_id', CHtml::listData(Yii::app()->user->um->listUsers(), 'iduser', 'username'), array('empty' => '- Seleccione -', 'class' => 'span12 fix')) ?>
        <div class="radio-list">
            <?php echo $form->radioButtonListRow($model, 'permisos', $model->permisosOpciones) ?>
            <input type="hidden" id="Tarea_permisos" value="<?php echo $model->permisos; ?>"/>
        </div>
    </div>
</div>

<div class="modal-footer">
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'type' => 'success',
        'icon' => 'ok',
        'label' => $model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),
        'htmlOptions' => array(
            'onClick' => 'js:AjaxAtualizacionInformacion("#contacto-form")')
    ));
    ?>
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'icon' => 'remove',
        'label' => Yii::t('AweCrud.app', 'Cancel'),
        'htmlOptions' => array('data-dismiss' => 'modal')
    ));
    ?>

</div>
<?php $this->endWidget(); ?>
